namespace net.podhola.gtd.finances

import System
import System.Collections
import net.podhola
import net.podhola.gtd

[Castle.ActiveRecord.ActiveRecord]
class PlannedIncome(Castle.ActiveRecord.ActiveRecordBase of PlannedIncome):
	_id as int	
	[Castle.ActiveRecord.PrimaryKey(Castle.ActiveRecord.PrimaryKeyType.Increment)]
	Id as int:
		get: return _id
		set: _id = value

	_subject as string	
	[Castle.ActiveRecord.Property] 
	Subject as string:
		get: return _subject
		set: _subject = value
	
	_expectedIncomeDate as DateTime
	[Castle.ActiveRecord.Property] 
	ExpectedIncomeDate as DateTime:
		get: return _expectedIncomeDate
		set: _expectedIncomeDate = value

	_plannedAccount as Account
	[Castle.ActiveRecord.BelongsTo("accountid")] 
	PlannedAccount as Account:
		get: return _plannedAccount
		set:
			_plannedAccount = value
			_plannedAccount.PlannedIncomes.Add( self )

	_completed as bool		
	[Castle.ActiveRecord.Property] 
	Completed as bool:
		get: return _completed
		set: _completed = value

	_receipts as IList = ArrayList()
	[Castle.ActiveRecord.HasMany(Receipt) ] 
	Receipts as IList:
		get: return _receipts
		set: _receipts = value
		
	_plannedAmount as double
	[Castle.ActiveRecord.Property] 
	PlannedAmount as double:
		get: return _plannedAmount
		set: _plannedAmount = value
		
	def GetAlreadyReceived():
		result = 0.0
		for receipt as Receipt in Receipts:
			result += receipt.Amount
		return result

	def Receive( amount as double, payiedDate as Nullable of DateTime, fromAccount as Account ):
		paiedBill = Receipt()
		paiedBill.HasCoveredPlannedIncome = self
		paiedBill.Amount = amount
		paiedBill.ToAccount = fromAccount
		paiedBill.ReceivedOn = DateTime.Now
		paiedBill.Subject = Subject
